PROC ?= $(shell sh scripts/print_proc.sh)
BIN ?= serv
HASH := $(shell sh -c 'git rev-parse --verify HEAD | cut -c 1-8')

analyse: ## 执行代码静态检查
	bash ./scripts/analyse.sh
.PHONY: analyse

test: ## 执行单元测试
	bash ./scripts/test.sh
.PHONY: test

precommit: analyse test ## commit检查（静态+单测）
.PHONY: precommit

bin:%:dist/$(PROC).$(BIN).$(HASH).bin ## 编译，环境变量BIN=serv
.PHONY: bin

dist/%.bin:
	bash ./scripts/build.sh

bin_cli:%:dist/$(PROC).cli/.$(HASH).wasbuilt ## 编译所有CLI程序
.PHONY: bin_cli

dist/$(PROC).cli/%.wasbuilt:
	bash ./scripts/build_cli.sh

testbin:%:dist/$(PROC).$(BIN).$(HASH).testbin
.PHONY: testbin

dist/%.testbin:
	bash ./scripts/buildtest.sh

local: bin ## 编译并link到本地(/data/svc/...)
	bash ./scripts/local.sh
.PHONY: local

local_cli: bin_cli ## 编译并link所有CLI程序到本地(/data/cli/...)
	bash ./scripts/local_cli.sh
.PHONY: local

remote: bin
	bash ./scripts/remote.sh
.PHONY: remote

image:
	bash ./scripts/image.sh
.PHONY: docker

.PHONY: help
# Absolutely awesome: http://marmelab.com/blog/2016/02/29/auto-documented-makefile.html
help:
	@grep -E '^[a-zA-Z_-]+:.*?## .*$$' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[36m%-30s\033[0m %s\n", $$1, $$2}'

.DEFAULT_GOAL := help
